package it.fuesi.myseries.model.adapters;

import it.fuesi.myseries.R;
import it.fuesi.myseries.model.Serie;

import java.util.ArrayList;

import com.loopj.android.image.SmartImageView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class SerieItemAdapter extends ArrayAdapter<Serie> {

	    private ArrayList<Serie> series;

	    
	    
	    public SerieItemAdapter(Context context, int textViewResourceId, ArrayList<Serie> series) {
	        super(context, textViewResourceId, series);
	    this.series = series;
	    }

	    @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        View v = convertView;
	    if (v == null) {
	            LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	            v = vi.inflate(R.layout.serie_list_item, null);
	    }
	            
	    Serie serie = series.get(position);
	    if (serie != null) {
	            TextView name = (TextView) v.findViewById(R.id.myserie_name);
	            SmartImageView banner = (SmartImageView) v.findViewById(R.id.myserie_banner);

	        if (name != null) {
	        	name.setText(serie.getName());
	        }
	        
	        if (banner != null) {
	        	banner.setImageUrl(serie.getBanner());
	        }

	    }
	    return v;
	    }
	
}
